﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using QLTB.Controllers;
using QuanLyThietBi.Manager;
using QuanLyThietBi.ManagerBase;
using QuanLyThietBi.HamXuLy;

namespace QLTB.Forms
{
    public partial class FrmNguoiQuanLy : DevComponents.DotNetBar.Office2007Form
    {
         
        TBL_NguoiQuanLyCtrl m_NguoiQuanLyCtrl = new TBL_NguoiQuanLyCtrl();
        FrmEditNguoiQuanLy m_frmEditNguoiQuanLy = null;


        public FrmNguoiQuanLy()
        {
            InitializeComponent();
        }

        private void FrmQuanLy_Load(object sender, EventArgs e)
        {
            LoadForm();
        }
        public void LoadForm()
        {
            m_NguoiQuanLyCtrl.HienthiDGV(dgvQuanLy, bnQuanLy);
        }
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            HamXuLy GetID = new HamXuLy();
            string sMaNguoiQL = GetID.LayMaID("P_GetMaNguoiQL");
            m_frmEditNguoiQuanLy = new FrmEditNguoiQuanLy(sMaNguoiQL, true);
            m_frmEditNguoiQuanLy.ThemEvent += new EventHandler(Them_Event);
            m_frmEditNguoiQuanLy.Text = "Thêm mới Nhóm quản lý thiết bị kỹ thuật";
            m_frmEditNguoiQuanLy.Show();
            
        }
        private void Them_Event(object sender, EventArgs e)
        {
            LoadForm();
        }

        private void bindingNavigatorEditItem_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection maQLselect = dgvQuanLy.SelectedCells;
            m_frmEditNguoiQuanLy = new FrmEditNguoiQuanLy(maQLselect[1].Value.ToString(), false);
            m_frmEditNguoiQuanLy.ThemEvent += new EventHandler(Them_Event);
            m_frmEditNguoiQuanLy.Text = "Hiệu chỉnh thông tin quản lý thiết bị kỹ thuật";
            m_frmEditNguoiQuanLy.Show();
        }

        private void btnrefresh_Click(object sender, EventArgs e)
        {
            LoadForm();
        }

        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            if (MessageBoxEx.Show("Bạn có chắc chắn xóa dòng này không?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dgvQuanLy.SelectedRows)
                {
                    m_NguoiQuanLyCtrl.XoaNguoiQuanLy(row.Cells[1].Value.ToString());
                }
            }
            LoadForm();
        }

        private void dgvQuanLy_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewSelectedCellCollection maQLselect = dgvQuanLy.SelectedCells;
            m_frmEditNguoiQuanLy = new FrmEditNguoiQuanLy(maQLselect[1].Value.ToString(), false);
            m_frmEditNguoiQuanLy.ThemEvent += new EventHandler(Them_Event);
            m_frmEditNguoiQuanLy.Text = "Hiệu chỉnh thông tin quản lý thiết bị kỹ thuật";
            m_frmEditNguoiQuanLy.Show();
        }

        private void bindingNavigatorExitItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnthemoi_Click(object sender, EventArgs e)
        {
            HamXuLy GetID = new HamXuLy();
            string sMaNguoiQL = GetID.LayMaID("P_GetMaNguoiQL");
            m_frmEditNguoiQuanLy = new FrmEditNguoiQuanLy(sMaNguoiQL, true);
            m_frmEditNguoiQuanLy.ThemEvent += new EventHandler(Them_Event);
            m_frmEditNguoiQuanLy.Text = "Thêm mới Nhóm quản lý thiết bị kỹ thuật";
            m_frmEditNguoiQuanLy.Show();
        }

        private void btnxoadong_Click(object sender, EventArgs e)
        {
            if (MessageBoxEx.Show("Bạn có chắc chắn xóa dòng này không?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dgvQuanLy.SelectedRows)
                {
                    m_NguoiQuanLyCtrl.XoaNguoiQuanLy(row.Cells[1].Value.ToString());
                }
            }
            LoadForm();
        }

        private void btnsuathongtin_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection maQLselect = dgvQuanLy.SelectedCells;
            m_frmEditNguoiQuanLy = new FrmEditNguoiQuanLy(maQLselect[1].Value.ToString(), false);
            m_frmEditNguoiQuanLy.ThemEvent += new EventHandler(Them_Event);
            m_frmEditNguoiQuanLy.Text = "Hiệu chỉnh thông tin quản lý thiết bị kỹ thuật";
            m_frmEditNguoiQuanLy.Show();
        }

        private void btnlammoi_Click(object sender, EventArgs e)
        {
            LoadForm();
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();

        }

       

      
    }
}